package com.edu.solr_news.util;

import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@Component //spring ioc容器管理
public class DateTimeUtil {

    public  String formatCSTDate(String cstDateStr) {
        Date date = null;
        SimpleDateFormat sdf1 = null;
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        try {
            sdf1 = new SimpleDateFormat("yyyy-MM-dd", Locale.UK);
            date = sdf1.parse(cstDateStr);
        } catch (ParseException e) {
            System.out.println("CST日期格式转换出错，原因：" + e.getMessage());
            return null;

        }
        return sdf2.format(date);
    }
}
